﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.KH.Contract;
using MaxLeaf.KH.BLLImplementation;
using CommonsLib.Utility;
using MaxLeaf.KH.DataContract;
using CommonsLib.Settings;

namespace MaxLeaf.KH.BLLProxy
{
    public class TestBLLProxy : BaseBLLProxy,IExecute, ITest
    {

        ITest bll;
        public TestBLLProxy():base()
        {
            switch ( Access_Mode )
            {
                
                case MaxLeaf.Commons.Enum.ACCESS_Direct:
                    {
                        bll = new TestBLL();
                        break;
                    }

                case MaxLeaf.Commons.Enum.ACCESS_IIS:
                    {
                        bll = new TestBLLWCFClient(this.WCF_Configs);
                        break;
                    }

                 
                default: throw new Exception(MaxLeaf.Commons.Const.EXCEPTION_MESSAGE_INVALID_ACCESSMODE_CONFIG);
            }
        }
        
        
        

        public override IDictionary<string, object> ExecuteCmd(string cmd, IDictionary<string, object> inputData)
        { 
                Dictionary<string, object> outputData = new Dictionary<string, object>();

                if (cmd.Equals("SayHello"))
                {
                    outputData["data"] = this.SayHello((TestModel)inputData["data"]);
                }
                else if (cmd.Equals("SelectDtl"))
                {
                    outputData["data"] = this.SelectDtl((TestModel)inputData["data"]);
                }
                else if (cmd.Equals("ShowError"))
                {
                    outputData["data"] = this.ShowError(inputData["data"].ToString());
                }
                else
                {
                    throw new Exception(string.Format(MaxLeaf.Commons.Const.EXCEPTION_MESSAGE_INVALID_COMMANDNAME, cmd));
                }


                return outputData;
            

        }

        public TestModel SayHello(TestModel user)
        {
            LogManager.Debug("BllproxySayHello ");
            return bll.SayHello(user);
        }

        public string ShowError(string strName)
        {
            return bll.ShowError(strName);
        }

        #region ITest 成员


        public List<object> SelectDtl(TestModel user)
        {
            return bll.SelectDtl(user);
        }

        #endregion
    }
}
